package com.czy.blog.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "sys_role")
public class Role implements Serializable
{
	private static final long serialVersionUID = -7196921380347413257L;
	
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid.hex")
	@Column(name = "ID")
	@Access(AccessType.PROPERTY)
	private String id;
	
	@Column(name="role_name")
	private String roleName;
	@Column(name="role_code")
	private String roleCode;
	
	@ManyToMany(fetch=FetchType.LAZY,mappedBy="roles")
	private Set<User> users;
	
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name = "sys_role_menu",joinColumns={@JoinColumn(name="role_id")},inverseJoinColumns={@JoinColumn(name="menu_id")})
	private Set<Menu> menus;
	
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name = "sys_role_func",joinColumns={@JoinColumn(name="role_id")},inverseJoinColumns={@JoinColumn(name="func_id")})
	private Set<Function> funcs;
	
	public String getId()
	{
		return id;
	}
	public void setId(String id)
	{
		this.id = id;
	}
	public String getRoleName()
	{
		return roleName;
	}
	public void setRoleName(String roleName)
	{
		this.roleName = roleName;
	}
	public String getRoleCode()
	{
		return roleCode;
	}
	public void setRoleCode(String roleCode)
	{
		this.roleCode = roleCode;
	}
	public Set<User> getUsers()
	{
		return users;
	}
	public void setUsers(Set<User> users)
	{
		this.users = users;
	}
	
	@Override
	public boolean equals(Object obj)
	{
		if(obj instanceof Role){
			Role role = (Role)obj;
			if(role.getId().equals(this.getId())){
				return true;
			}
		}
		
		return false;
	}
	
	@Override
	public int hashCode()
	{
		return this.id.hashCode();
	}
	public Set<Menu> getMenus()
	{
		return menus;
	}
	public void setMenus(Set<Menu> menus)
	{
		this.menus = menus;
	}
	public Set<Function> getFuncs()
	{
		return funcs;
	}
	public void setFuncs(Set<Function> funcs)
	{
		this.funcs = funcs;
	}
	
}
